package com.ly.spring;

import com.ly.spring.biz.UserBiz;
import com.ly.spring.mapper.UserMapper;
import com.ly.spring.web.UserAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;

@Configuration
@ComponentScan("com.ly.spring")
public class AnnoConfig {

    @Bean(initMethod = "init",destroyMethod = "destroy")
    @Lazy
    @Scope("prototype")
    public Demo demo(){
        Demo demo = new Demo();
        demo.setName("张三");
        return demo;
    }


    @Bean(initMethod = "init",destroyMethod = "destroy")
    @DependsOn("newDemo")
    public Demo newDemo1(){
        Demo demo = new Demo();
        demo.setName("王五");
        return demo;

    }

    @Bean(initMethod = "init",destroyMethod = "destroy")
    @Primary
    public Demo newDemo(){
        Demo demo = new Demo();
        demo.setName("李四");
        return demo;

    }

    @Bean
    public UserMapper userMapper(){
        return new UserMapper();
    }


    @Autowired
    UserMapper userMapper;
    @Bean
    public UserBiz userBiz(){
        UserBiz userBiz = new UserBiz();
        userBiz.setUserMapper(userMapper);
        return new UserBiz();
    }

    @Bean
    public UserAction userAction(){
        UserAction userAction = new UserAction();
        userAction.setUserBiz(new UserBiz());
        userAction.getUserBiz().setUserMapper(new UserMapper());

        return new UserAction();
    }

}
